package com.gzzq.controller;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gzzq.entity.QueueType;
import com.gzzq.entity.QueueVO;
import com.gzzq.service.Producer;
import com.gzzq.util.ResponseUtil;

/**
 * 消息入队接口
 * @author huanghp
 */
@Controller
@RequestMapping(value = "/producer")
public class ProductController {
	@Autowired Producer producer;
	
	@RequestMapping(value = "/send", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> sendMessage(@RequestBody QueueVO vo) {
		String queueName = null;
		if (StringUtils.isBlank(vo.getQueueType())) {
			return ResponseUtil.falseBizResult(">>>>>>>请传入消息类型：>>>>>>>>>>>:queueType");
		}
		if (StringUtils.isBlank(vo.getMsg())) {
			return ResponseUtil.falseBizResult(">>>>>>>请传入消息体：>>>>>>>>>>>:msg");
		}
		if ("1".equals(vo.getQueueType())) {
			QueueType queueType = QueueType.INTEGRAL_QUEUE;
			queueName = queueType.toString();
		}
		if ("2".equals(vo.getQueueType())) {
			QueueType queueType = QueueType.MESSAGE_QUEUE;
			queueName = queueType.toString();
		}
		try {
			producer.sendMessage(queueName, vo);  
			return ResponseUtil.trueBizResult("消息入队成功!!!");
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseUtil.falseTipResult("消息：" + vo.getMsg() + ">>>>>>>>>>入队失败,请检查服务!!!!");
		}
	}
}
